/**
 * 开始录音
 * @param { number } duration 录音的时长，单位 ms
 * @param { number } sampleRate 采样率（pc不支持）
 * @param { number } numberOfChannels 录音通道数
 * @param { number } encodeBitRate 编码码率
 * @param { string } format 音频格式
 * @param { string } audioSource 指定录音的音频输入源
 */
export function startRecorder({duration, sampleRate, numberOfChannels, encodeBitRate, format, audioSource}) {
	return new Promise(resolve => {
		wx.getRecorderManager().start({
			duration : duration || 6e4,
			sampleRate : sampleRate || 8e3,
			numberOfChannels : numberOfChannels || 2,
			encodeBitRate : encodeBitRate || 48e3,
			format : format || 'aac',
			audioSource : audioSource || 'auto',
			success (res) {
				console.log(res);
				resolve(res)
			},
			fail(err){
				console.log(err);
				resolve(err);
			}
		});
	})
}

/**
 * 暂停录音
 */
export function pauseRecorder() {
	return new Promise(resolve => {
		wx.getRecorderManager().pause();
		resolve("pauseRecorder:ok")
	})
}

/**
 * 继续录音
 */
export function resumeRecorder() {
	return new Promise(resolve => {
		wx.getRecorderManager().resume();
		resolve("resumeRecorder:ok")

	})
}

/**
 * 结束录音
 */
export function stopRecorder() {
	return new Promise(resolve => {
		let recorderManager = wx.getRecorderManager();
		recorderManager.onStop((res) => {
			resolve(res);
		})
		recorderManager.stop();
	})
}
